package com.ghsc.ghxc.jsb.ui.live.view

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.cn.appcore.ext.loge
import com.cn.appcore.ext.setSingleClickListener
import com.cn.appcore.ext.showToast
import com.cn.appcore.utils.GsonUtil
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ext.http.request
import com.ghsc.ghxc.jsb.ui.live.activity.ShareFriendsListActivity
import com.ghsc.ghxc.jsb.ui.live.activity.ShareGroupListActivity
import com.ghsc.ghxc.jsb.ui.live.bean.LiveExtendDataBean
import com.lxj.xpopup.core.BottomPopupView

/**
 * 项目：JingShortVideo
 * 包名：com.bbl.jyShortVideo.ui.video.live.view
 * 类名：LiveSharePopupView
 * 创建时间：2022/12/21 17:00
 * 创建人 @author： xiaolin
 * 描述 ：Todo...分享
 */
class LiveSharePopupView(context: AppCompatActivity, url:String,httpUrl:String,anchorId:String,liveID:String,liveExtBean: LiveExtendDataBean,title:String) : BottomPopupView(context) {



    override fun getImplLayoutId() = R.layout.live_share
    private val mContext = context

    val url = url
    val httpUrl = httpUrl
    val streamid = anchorId
    val liveID= liveID
    val liveExtBean: LiveExtendDataBean = liveExtBean
    val title:String= title

    override fun onCreate() {
        super.onCreate()
        findViewById<TextView>(R.id.tvCopy).setSingleClickListener {
//            val map: HashMap<String, Any> = HashMap()
//            map["streamid"] = streamid
//            map["content"] =url
//            val json=  GsonUtil.mapToJsonStrObjEncryption(map)
//            mContext.request({ ApiMarket.service.onLiveShareData(json!!) }, { data ->
//                var str=httpUrl+"&sid="+streamid
//                loge("分享链接111="+data.toString())
//                loge("分享链接22="+str)
//                val myClip = ClipData.newPlainText("text", str)
//                val myClipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
//                myClipboard.setPrimaryClip(myClip)
//                showToast("复制成功")
//                dismiss()
//            })
        }
        findViewById<TextView>(R.id.tvShareFriends).setSingleClickListener {
            val intent = Intent(context, ShareFriendsListActivity().javaClass)
            var  bundle = Bundle()
            bundle.putString("url", "$httpUrl&sid=$streamid")
            bundle.putString("liveID", liveID)
            bundle.putString("userNick", liveExtBean.userNick)
            bundle.putString("userAvatar", liveExtBean.userAvatar)
            bundle.putString("coverUrl", liveExtBean.cover_url)
            bundle.putString("liveTitle", title)
            bundle.putString("anchorId", streamid)
            bundle.putInt("signIndex", 1)
            intent.putExtras(bundle)
            context!!.startActivity(intent)
            dismiss()
        }
        findViewById<TextView>(R.id.tvShareGroup).setSingleClickListener {
            val intent = Intent(context, ShareGroupListActivity().javaClass)
            var  bundle = Bundle()
            bundle.putString("url", "$httpUrl&sid=$streamid")
            bundle.putString("liveID", liveID)
            bundle.putString("userNick", liveExtBean.userNick)
            bundle.putString("userAvatar", liveExtBean.userAvatar)
            bundle.putString("coverUrl", liveExtBean.cover_url)
            bundle.putString("liveTitle", title)
            bundle.putString("anchorId", streamid)
            bundle.putInt("signIndex", 1)
            intent.putExtras(bundle)
            context!!.startActivity(intent)
            dismiss()
        }
        findViewById<TextView>(R.id.tvBtnCancel).setSingleClickListener {
            dismiss()
        }
    }

    override fun getMaxWidth() = 0
}